//pk_answer_user 被追答的人的pk
var pk_answer_user = null;
var pk_sool_answer = null;

var getinfo = function(){
    //获取追问追答的内容
    $.ajax({
        type : "POST",
        url : WebSite.AskerHandlingPage.searchquestion_detail,
        dateType : "json",
        data:{
            "pk_question":getUrlParam("pk_question")
        },
        success : function(result){
            var myTemplate = Handlebars.compile($("#handling-template").html());
            $("#handling-info").html(myTemplate(result));
        },
        error : function () {
            alert("问题的详细信息未获取到");
        }
    });

};


var willhide = null;
//点击追问按钮，弹出追问的编辑器
$("#handling-info").on("click",".addquestion",function(){
    var pk_sool_answer = $(this).attr("pk_sool_answer");
    pk_answer_user = $(this).attr("pk_answer_user");
    willhide = $(this).attr("pk_sool_answer");
    //alert(pk_answer_user);
    var parentDiv = $("#editordisplay").parent("div");
    var editorHTML = parentDiv.html();
    parentDiv.html("");
    $("#"+pk_sool_answer).html(editorHTML);
    //初始化编辑器
    var contentEditorUM = UM.getEditor("contentEditor");
    //隐藏继续追问和采纳答案按钮
    $("."+pk_sool_answer).hide();
});


//点击采纳按钮，采纳该回答
$("#handling-info").on("click",".submitThisAnswer",function(){
    var pk_answer = $(this).attr("adopt_answer_pk");
    //然后跳到已解决页面，把pk_answer传过去，判断pk_answer不为空，再进行异步刷新
    window.location.href = WebSite.AskerSolvedPage.url + "&pk_answer=" + pk_answer + "&pk_question=" + getUrlParam("pk_question");
});

var test = new Array();

//追问
var submitAddQuestion = function(){
if(!test[pk_answer_user]){
    $.ajax({
        url          : WebSite.AskerHandlingPage.addQuestion,
        type         : "post",
        dataType     : "json",
        data         : {
            "pk_sool_question"    : getUrlParam("pk_question"),
            "pk_answer_user" : pk_answer_user,
            "old_fileName":$("#old_fileName").text(),
            "new_file_url":$("#new_file_url").text(),
            "description"    : $("#contentEditor").html()
        },
        success      : function(result){
            if(result.success){
                //追加我的追答
                var myQuestionTemplate = Handlebars.compile($("#addQuestionTemplate").html());
                $("#storeAddQuestion" + pk_answer_user).append(myQuestionTemplate(result));
                //reflash page
                location.reload();
                //清空编辑器
                $("#contentEditor").html("");
		        //把文本编辑器放回原处
                $("#editordisplay").html($("#"+pk_sool_answer).html());
                //把该处的编辑器隐藏
                $("#"+willhide).hide();
                test[pk_answer_user] = result.success;
                //显示继续追问和采纳答案按钮
                $(".dq-frame-left-answer-detail-add").show();
                $(".dq-frame-left-answer-detail-agree").show();
            }else{
                alert(result.msg);
            }
        }

    });
    }else{
        alert("您已经追问过一次了，不能连续追问");
        //清空编辑器
        $("#contentEditor").html("");
        //把文本编辑器放回原处
        $("#editordisplay").html($("#"+pk_sool_answer).html());
        //把该处的编辑器隐藏
        $("#"+willhide).hide();
    }
};

//弹出附件上传
function getUpload(){
    $(".uploadDisplay").addClass("uploadDisplay-block");
};

//显示遮罩层
function upload_adenexa_show(){
    $("#covered").show();
    $("#poplayer").show();
}
/**
 * 关闭遮罩层
 */
function close_upload(){
    $("#covered").hide();
    $("#poplayer").hide();

}